#$Source: Volumes://MATEOR/prlserverapi/prlserverapi-gui.rc/sainitial.pm$
#$Date: June 18, 2012$
#$Revision: 0.01-0a$

use strict;
package sainitial;

sub page{
  my($r) = @_;
  my $content = <<EOF;
    <!DOCTYPE html>
    <html>
      <head>
        <title>PrlServerAPI web based GUI API Example application - Pizza cost calculator</title>
        <script language="javascript">
          function xmlhttpPost(strURL, div_id) {
            var xmlhttp;
            var self = this;
            var oDiv = document.getElementById(div_id);
            if(window.XMLHttpRequest){
              self.xmlhttp = new XMLHttpRequest();
            }
            self.xmlhttp.open('GET', strURL, true);
            self.xmlhttp.setRequestHeader('Content-Type', 'text/html');
            self.xmlhttp.onreadystatechange = function(){
              if(self.xmlhttp.readyState == 4){
                updatepage(self.xmlhttp.responseText, oDiv);
              }
            }
            self.xmlhttp.send();
          }
          function updatepage(str, div){
            document.getElementById(div).innerHTML = str;
          }
        </script>
      </head>
      <body>
        <div id="dyn">
          <form id="myForm">
            Total cost: <input name="cost" /><br />
            Number of eaters: <input name="num" /><br />
            <input type=button value="Calculate!" onclick="javascript:xmlhttpPost('/sampleapp.calc?cost='+document.forms['myForm'].cost.value+'&num='+document.forms['myForm'].num.value, 'dyn');" />
          </form>
        </div>
      </body>
    </html>
EOF
  return $content;
}
  
1;
